#!/usr/bin/env python
'''
cluster-creator
Copyright 2009 Adam Drew

This file is part of cluster-creator.

cluster-creator is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

cluster-creator is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with cluster-creator.  If not, see <http://www.gnu.org/licenses/>.
'''

import os
import sys
import xml.dom.minidom

documentObject = xml.dom.minidom.parse("fence_xvm.xml")

def multiList(xDepth, yDepth):
	temp = [None] * yDepth
	for i in range(yDepth):
		temp[i] = [None] * xDepth
	return temp

def xmlQuery(blockToGrab, multiList):
	xPos = 0
	yPos = 0
# This looks nasty but aint bad. All of this is needed to traverse the DOM.
# Better way? Maybe; but I couldn't suss it :)
	for topLevelNodes in documentObject.childNodes:
		if topLevelNodes.localName != None:
			for mainNodes in topLevelNodes.childNodes:
				if mainNodes.localName != None:
					if mainNodes.localName == blockToGrab:
						for paramNodes in mainNodes.childNodes:
							if paramNodes.localName != None:
								multiList[yPos][xPos] = paramNodes.localName
								for paramValues in paramNodes.attributes.keys():
									if paramValues != "assignment":	
										xPos+=1
										multiList[yPos][xPos] = paramValues
									xPos+=1
									if paramNodes.attributes[paramValues].value == "?":
										multiList[yPos][xPos] = raw_input("Please input a value for %s : " % multiList[yPos][xPos-1])
									else:
										multiList[yPos][xPos] = paramNodes.attributes[paramValues].value
								xPos = 0
								yPos+=1
	
fenceParams = multiList(100,100)

xmlQuery("fencedevice-paramaters", fenceParams)

print fenceParams[1][0]
